<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title><?=getValInArr(getSess(SESS_DIC),array('webInfo','webtitle'))?></title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <script src="<?php echo base_url().'public/home/js/' ?>jquery.js"></script>
    <?php 
        include_once "public/home/html/alert.php" ;
     ?>
    <script type="text/javascript" src="<?php echo base_url().'public/home/js/' ?>function.js"></script>
    <?php include_once "public/home/html/broadcast.php"  ?>
    <link rel="stylesheet" href="<?php echo base_url().'public/home/css/' ?>index.css">
    <?php include_once "public/home/html/bootstrap.php"  ?>
    <style>
        .search-border{
            background: #eaeaea;
            border-radius: 20px;
            height: 50px;
            margin-top: 50px;
        }
        .search-border img{
            width: 20px;
            margin-left: 20px;
        }
        .search-border input{
            height: 44px;
            margin-top: 3px;
            margin-left: 15px;
            border: none;
            background: #eaeaea;
            width: 80%;
        }
        .search-list div{
            height: 40px;
            line-height: 40px;
            text-align: center;
            border-bottom: 1px solid #ececec;
        }
    </style>
</head>
<body>
    <input type="hidden" name="url" id="url"value="<?php echo base_url()?>">
    <input type="hidden" name="type" id="type" value="<?=$type?>">
    <input type="hidden" name="" value="<?=SearchType::First[XPHEnum::Value]?>" id="type1">
    <input type="hidden" name="" value="<?=SearchType::Second[XPHEnum::Value]?>" id="type2">
    <input type="hidden" name="type" id="class_name" value="<?=$class_name?>">
    <input type="hidden" name="type" id="teacher_name" value="<?=$teacher_name?>">
    <div class="search-border" oninput="getSearchList()">
        <img src="<?=base_url()?>public/home/images/search-icon.png">
        <input type="" name="" id="search" data-id="" placeholder="<?php echo $type==SearchType::First[XPHEnum::Value]? '请输入课程名称':'请教师名称' ?>">
    </div>
    <div class="search-list">
        
    </div>

    <script>
        $("body").keydown(function() {
            if (event.keyCode == "13") {//keyCode=13是回车键    
                backSearch();
            }
         });
        // 获取搜索列表
        function getSearchList(){
            var type=$("#type").val();
            $.ajax({
                url: $("#url").val()+'/Home/Search/getList',
                type: 'POST',
                dataType: 'json',
                data: {
                    value: $("#search").val(),
                    type:type
                },
                success:function(data){
                    var t=JSON.parse(data.v);
                    if(data.status){
                        var html='';
                        if(type==$("#type1").val()){
                            $.each(t, function(k, v) {
                                 html+="<div onclick='getValue(this)' data-value='"+v['name']+"' data-id='"+v['id']+"'>"+v['name']+"</div>";
                            });
                        }else{
                            $.each(t, function(k, v) {
                                 html+="<div onclick='getValue(this)' data-value='"+v['username']+"' data-id='"+v['id']+"'>【"+v['usercode']+"】"+v['username']+"</div>";
                            });
                        }
                        $(".search-list").html(html);
                    }
                }
            })            
        }
        // 返回输入页
        function backSearch(){   
            var class_name=getURLParameter(window.location.href,'class_name');
            var teacher_name=getURLParameter(window.location.href,'teacher_name'); 
            var class_id=getURLParameter(window.location.href,'class_id');
            var teacher_id=getURLParameter(window.location.href,'teacher_id');
            if(class_name==undefined){
                class_name='';
            }
            if(teacher_name==undefined){
                teacher_name='';
            }
            if(teacher_id==undefined){
                teacher_id='';
            }
            if(class_id==undefined){
                class_id='';
            }
           
            if($("#type").val()==$("#type1").val() && $("#search").val()!=undefined && $("#search").val()!=''){
                class_name=encodeURI($("#search").val());       
                class_id=encodeURI($("#search").attr('data-id'));        
            }
            if($("#type").val()==$("#type2").val() && $("#search").val()!=undefined && $("#search").val()!=''){
                // teacher_name='teacher_name='+encodeURI($("#search").val())+'&teacher_id='+encodeURI($("#search").attr('data-id'));
                teacher_name=encodeURI($("#search").val());       
                teacher_id=encodeURI($("#search").attr('data-id'));        
            }
            var href=getRootPath()+'/Home/Class_Assess/ClassIndex?class_name='+class_name+'&class_id='+class_id+'&teacher_name='+teacher_name+'&teacher_id='+teacher_id;

            location.href=href;
         }
        
        // 点击搜索列表值，赋值到input上
        function getValue(obj){
            $("#search").val($(obj).attr('data-value'));
            $("#search").attr('data-id',$(obj).attr('data-id'));
            backSearch();
        }
    </script>

</body>
</html>
